﻿Public Class SubDetalleCobroDAO
    Public Shared Function insertarSubDetalleCobro(ByVal DetalleCobroId As Integer, ByVal TipoMovimientoId As Integer, ByVal SubDetalleCobroMonto As Double, ByVal SubDetalleCobroObservaciones As String) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_SubDetalleCobro"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.INSERTAR).DbType = DbType.Int32
                    .AddWithValue("@SubDetalleCobroId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@DetalleCobroId", DetalleCobroId).DbType = DbType.Int32
                    .AddWithValue("@TipoMovimientoId", TipoMovimientoId).DbType = DbType.Int32
                    .AddWithValue("@SubDetalleCobroMonto", SubDetalleCobroMonto).DbType = DbType.Double
                    .AddWithValue("@SubDetalleCobroObservaciones", SubDetalleCobroObservaciones).DbType = DbType.String
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function obtenerSubDetallesCobro(ByVal SubDetalleCobroId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_subDetalleCobro_obtener", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@SubDetalleCobroId", SubDetalleCobroId).DbType = DbType.Int32
            da.Fill(ds, "SubDetallesCobro")

            Return ds.Tables("SubDetallesCobro")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    'Public Shared Function obtenerSubDetalleCobrosXFiltro(ByVal ObraSocialXPlanId As Integer, ByVal Mes As Integer, ByVal Ano As Integer) As DataTable
    '    Dim cn As SqlClient.SqlConnection = Nothing
    '    Try
    '        cn = Conexion.Conectar
    '        Dim ds As New DataSet
    '        Dim da As New SqlClient.SqlDataAdapter("usp_SubDetalleCobro_obtenerXFiltro", cn)
    '        da.SelectCommand.CommandType = CommandType.StoredProcedure
    '        da.SelectCommand.Parameters.AddWithValue("@ObraSocialXPlanId", ObraSocialXPlanId).DbType = DbType.Int32
    '        da.SelectCommand.Parameters.AddWithValue("@Mes", Mes).DbType = DbType.Int32
    '        da.SelectCommand.Parameters.AddWithValue("@Ano", Ano).DbType = DbType.Int32
    '        da.Fill(ds, "SubDetalleCobros")

    '        Return ds.Tables("SubDetalleCobros")
    '    Catch ex As Exception
    '        'GUARDAMOS EL ERROR EN LA BD
    '        ErrorDAO.insertarError(ex)
    '        Return Nothing
    '    Finally
    '        Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
    '    End Try
    'End Function

    Public Shared Function actualizarSubDetalleCobro(ByVal SubDetalleCobroId As Integer, ByVal DetalleCobroId As Integer, ByVal TipoMovimientoId As Integer, ByVal SubDetalleCobroMonto As Double, ByVal SubDetalleCobroObservaciones As String) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_SubDetalleCobro"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@SubDetalleCobroId", SubDetalleCobroId).DbType = DbType.Int32
                    .AddWithValue("@DetalleCobroId", DetalleCobroId).DbType = DbType.Int32
                    .AddWithValue("@TipoMovimientoId", TipoMovimientoId).DbType = DbType.Int32
                    .AddWithValue("@SubDetalleCobroMonto", SubDetalleCobroMonto).DbType = DbType.Double
                    .AddWithValue("@SubDetalleCobroObservaciones", SubDetalleCobroObservaciones).DbType = DbType.String
                End With
                .Connection = cn
                .ExecuteNonQuery()

            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function eliminarSubDetalleCobro(ByVal SubDetalleCobroId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_SubDetalleCobro"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ELIMINAR).DbType = DbType.Int32
                    .AddWithValue("@SubDetalleCobroId", SubDetalleCobroId).DbType = DbType.Int32
                    .AddWithValue("@DetalleCobroId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@TipoMovimientoId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@SubDetalleCobroMonto", Constante.MENOSUNO).DbType = DbType.Double
                    .AddWithValue("@SubDetalleCobroObservaciones", Constante.VACIO).DbType = DbType.String
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With

            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function
End Class
